//
// Created by Semir on 2020/5/16.
//

#include <iostream>
#include <vector>

using namespace std;

bool VerifySquenceOfBST(vector<int>& sequence, int rootIndex, int low) {
    if (rootIndex == low) {
        return true;
    }
    int i;
    for (i = low; i < rootIndex && sequence[i] < sequence[rootIndex]; i++) {}
    int mid = i;
    for (; i < rootIndex; i++) {
        if (sequence[i] < sequence[rootIndex]) {
            return false;
        }
    }
    bool res = false;
    if (mid > low) {
        res = res || VerifySquenceOfBST(sequence, mid - 1, low);
    }
    if (mid < rootIndex) {
        res = res || VerifySquenceOfBST(sequence, rootIndex - 1, mid);
    }
    return res;
}

bool VerifySquenceOfBST(vector<int> sequence) {
    if (sequence.empty()) {
        return false;
    }
    return VerifySquenceOfBST(sequence, sequence.size() - 1, 0);
}

int main() {
    vector<int> sequence = {};
    bool res = VerifySquenceOfBST(sequence);
    cout << res << endl;
    return 0;
}